package com.example.cyw.mycontextprover;

import android.content.ContentValues;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends AppCompatActivity {
       private EditText ed_id;
       private EditText ed_name;
      private EditText ed_age;
    private Button btn_add;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        initView();
        btn_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri=Uri.parse(MyContentProvider.URI_STUDENT);
               String str_id =String.valueOf(ed_id.getText());
                int id=Integer.parseInt(str_id);
                String name=String.valueOf(ed_name.getText());
                String str_age =String.valueOf(ed_age.getText());
                int age=Integer.parseInt(str_age);
                ContentValues values=new ContentValues();
                values.put("id",id);
                values.put("name",name);
                values.put("age",age);
                getContentResolver().insert(uri,values);
                finish();

            }
        });
    }

    private void initView() {
        ed_id= (EditText) findViewById(R.id.id);
        ed_name= (EditText) findViewById(R.id.name);
        ed_age= (EditText) findViewById(R.id.age);
        btn_add= (Button) findViewById(R.id.btn_add);
    }
}
